﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ProgramMain.Classifiers;
using ProgramMain.Database;
using ProgramMain.Framework;

namespace ProgramMain.OpticNet
{
    public partial class CableBoxCombo : ProgramMain.Framework.BaseComboBoxViewCtl
    {
        public CableBoxCombo()
        {
            InitializeComponent();
        }

        private CableBoxKinds m_CableBoxKind = CableBoxKinds.CableBox;
        public CableBoxKinds CableBoxKind
        {
            get { return m_CableBoxKind; }
            set { m_CableBoxKind = value; }
        }

        override protected void LoadData()
        {
            if (DetailID.HasValue)
            {
                cableBoxesTableAdapter.SelectCommandTimeout = Properties.Settings.Default.LongQueryTimeout;
                cableBoxesTableAdapter.Fill(simpleOpticNetDB.CableBoxes, null, DetailID, Convert.ToInt32(m_CableBoxKind));
            }
        }

        protected override void UpdateData()
        {
            //внести изменения в базу
            this.cableBoxesTableAdapter.SetUpdateTimeout = ProgramMain.Properties.Settings.Default.LongQueryTimeout;
            this.cableBoxesTableAdapter.Update(this.simpleOpticNetDB.CableBoxes);
        }
        
        override protected BaseModalDetailCtl CreateDetailDialog(BaseModalDetailCtl.ShowModeTypes pShowMode)
        {
            return new CableBoxDetail(m_CableBoxKind);
        }

        override protected void PreCreateDetailDialog(BaseModalDetailCtl.ShowModeTypes pShowMode, DataRowView RowView)
        {
            if (pShowMode == BaseModalDetailCtl.ShowModeTypes.Add && RowView != null && DetailID.HasValue)
            {
                SimpleOpticNetDB.CableBoxesRow row = (SimpleOpticNetDB.CableBoxesRow)RowView.Row;
                row.VertexID = DetailID.Value;
            }
        }

        private void CableBoxCombo_DetailIDChanged(object sender, DetailEventArgs e)
        {
            DBRead();
        }
    }
}
